﻿using System;
using System.Collections.Generic;
using System.Linq;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;
using ProbeMod.StatusEffects;

namespace ProbeMod.Cards
{
    public sealed class ProbeEnTaroTassadarDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();

            config.Rarity = Rarity.Rare;
            config.Type = CardType.Skill;
            config.TargetType = TargetType.Nobody;
            config.Colors = new List<ManaColor>() { ManaColor.Blue };

            config.Cost = new ManaGroup() { Blue = 2,Any = 1 };
            config.UpgradedCost = new ManaGroup() { Blue = 1 };

            config.Value1 = 2;
            config.Value2 = 2;

            config.RelativeCards = new List<string>() { "ProbeZealotCharge" };
            config.UpgradedRelativeCards = new List<string>() { "ProbeZealotCharge" };

            config.Index = CardIndexGenerator.GetUniqueIndex(config);
            return config;
        }
    }

    /// <summary>
    /// 堂口兄弟
    /// </summary>
    [EntityLogic(typeof(ProbeEnTaroTassadarDef))]
    public sealed class ProbeEnTaroTassadar : ProbeCard
    {
        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            var handFriend = Battle.HandZone.Where(c => c.CardType == CardType.Friend).ToList();

            yield return new DiscardManyAction(Battle.HandZone);

            foreach (var card in handFriend)
            {
                if (card.Config.RelativeEffects.Contains("ProbeBuildingKeywordSe"))
                    yield return new AddCardsToDrawZoneAction(Library.CreateCards<ProbeZealotCharge>(Value2), DrawZoneTarget.Random);
                yield return new AddCardsToHandAction(Library.CreateCards<ProbeZealotCharge>(Value1));
            }

        }
    }
}
